PASO 4: ¿Notaste el texto verde en la primera línea de la función principal? Este texto es una cadena de documentos.
Una cadena de documentación es un tipo especial de comentario que explica y documenta lo que hace una función.
Agreguemos una cadena de documentación a set_stage() ya que no tenemos una allí. ¡Pondremos uno debajo de cada función!
Ir a y arrastre Docstring para que sea la primera línea con sangría debajo de set_stage() .
Cambie el texto dentro de la cadena de documentación para que diga """ Sets up the stage for the game """ .
To navigate the page using the TAB key, first press ESC to exit the code editor.
def set_stage():
stage.set_background("soccerfield")
stage.disable_floor()
def main():
""" Sets up the program and calls other functions """
set_stage()
main()
t = codesters.Teacher()
defs = t.find_block("def")
docstrings = t.find_text('"""')
num_docstrings = len(docstrings)
default_doc = '""" This is a description of what this function does """'.replace(' ','').lower()
def above_def(line_number, def_list):
""" Returns the name of the nearest function and the distance above the given line number """
function_name = ""
distance = line_number - def_list[0][0]
for func in def_list:
if line_number - func[0] <= distance and line_number - func[0] > 0:
function_name = func[1]
distance = line_number - func[0]
return function_name, distance
num_docstrings = len(docstrings)
test_strings = ['set', 'up', 'stage'] #'Sets up the stage for the game'
try:
text = docstrings[0][1]
text = text.replace(' ','').lower()
line_number = docstrings[0][0]
indent = t.get_indent_at_line(line_number)
except:
text = "DNE"
line_number == "DNE"
indent = "DNE"
try:
func, distance = above_def(docstrings[0][0], defs)
except:
func = "DNE"
distance = "DNE"
t1 = TestObjective()
t1.add_success(num_docstrings > 1, "Great job!")
t1.add_failure(num_docstrings == 1, "Did you add a Docstring under set_stage()?")
t1.add_failure(num_docstrings == 0, "Oops. Did you delete a docstring?")
t2 = TestObjective()
t2.add_success(text != default_doc and num_docstrings > 1, "Great job!")
t2.add_failure(text == default_doc, "Did you change the docstring to describe the function?")
t2.add_failure(num_docstrings == 1, "Did you add a Docstring under set_stage()?")
t3 = TestObjective()
t3.add_success(indent == 4 and num_docstrings > 1, "Great job!")
t3.add_failure(indent < 4, "Did you indent the docstring inside set_stage()?")
t3.add_failure(indent > 4, "Oops, did you indent the docstring more than once?")
t3.add_failure(indent == "DNE", "Did you indent the docstring inside set_stage()?")
t3.add_failure(num_docstrings == 1, "Did you add a Docstring under set_stage()?")
t4 = TestObjective()
t4.add_success("set_stage" in func and distance < 5, "Great job!")
t4.add_failure("set_stage" not in func, "Did you place the docstring under set_stage()?")
t4.add_failure(distance >= 5, "Make sure the docstring is at the top of the function!")
t4.add_failure(func == "DNE", "Did you delete a docstring?")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4])
tester.run_tests()
tester.display_first_feedback()
Are you already running a Codesters project in another tab or window?
Micro:bit can only connect to one web page at a time.
Try stopping other Codesters projects or closing
other tabs or windows that may be using your Micro:bit.
If that doesn't fix the problem try disconnecting your Micro:bit,
reloading this page, and reconnecting your Micro:bit.